package cn.hxcx.top.modules.dvc.web;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.hxcx.top.common.persistence.Page;
import cn.hxcx.top.modules.dvc.entity.DeviceInfo;
import cn.hxcx.top.modules.dvc.service.DeviceInfoService;
import cn.hxcx.top.modules.sys.service.SystemService;

@Controller
@RequestMapping(value = "${frontPath}/entrance/dvc")
public class DeviceInfoAjaxController {
	@Autowired
	private DeviceInfoService deviceInfoService;
	@Autowired
	private SystemService systemService;

	@ResponseBody
	@RequestMapping(value = "ajaxGetList")
	public Map<String, Object> ajaxGetList(Map<String, String> params) {
		Map<String, Object> map = new HashMap<String, Object>();
		if (StringUtils.isBlank(params.get("uid")) || StringUtils.isBlank(params.get("userToken"))
				|| !systemService.checkMobileLogin(params.get("uid"), params.get("userToken"))) {
			map.put("resault", "2");
			map.put("msg", "尚未登录或异地登录！请重新登录");
			return map;
		}
		DeviceInfo deviceInfo = new DeviceInfo();
		Page<DeviceInfo> page = new Page<DeviceInfo>();
		deviceInfo.setPage(page);
		page.setPageSize(10);
		page.setPageNo(Integer.parseInt(params.get("pages")));
		page.setList(deviceInfoService.findAjaxList(params));
		map.put("resault", "1");
		map.put("data", page.getList());
		return map;
	}
	
	@ResponseBody
	@RequestMapping(value = "ajaxGetInfo")
	public Map<String, Object> ajaxGetInfo(Map<String, String> params) {
		Map<String, Object> map = new HashMap<String, Object>();
		if (StringUtils.isBlank(params.get("uid")) || StringUtils.isBlank(params.get("userToken"))
				|| !systemService.checkMobileLogin(params.get("uid"), params.get("userToken"))) {
			map.put("resault", "2");
			map.put("msg", "尚未登录或异地登录！请重新登录");
			return map;
		}
		DeviceInfo deviceInfo = deviceInfoService.get(params.get("id"));
		map.put("resault", "1");
		map.put("data", deviceInfo);
		return map;
	}
}
